package com.foreknow.controller;

import com.foreknow.model.Admin;
import com.foreknow.service.AdminService;
import com.foreknow.service.impl.AdminServiceImpl;
import sun.util.locale.LocaleUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置服务器端向客户端响应的内容的类型
        resp.setContentType("text/html;charset=utf-8");
        //客户端向服务器端请求的字符编码集
        req.setCharacterEncoding("utf-8");
        PrintWriter out = resp.getWriter();
        //如何获取到请求的参数
        String username= req.getParameter("username");
        String password= req.getParameter("password");

//        out.println("email: "+email+"<br>");
//        out.println("password: "+password+"<br>");
        //调用Service
        AdminService service = new AdminServiceImpl();
        Admin admin = service.isValidate(username,password);
        if(admin!=null){
            req.getRequestDispatcher("/user/manager?q=list").forward(req,resp);
        }else {
            out.println("登录失败......");
        }
    }
}
